home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gui4cli / ext / gcview / gcview.gc < prev    next >
Text File  |  1999-04-29  |  16KB  |  736 lines

  1. G4C
  2.  
  3. ; ******************** This is a Gui4Cli gui *********************
  4.  
  5. ; - You need Gui4Cli version 3.7+ to run it 
  6. ; - Get it from Aminet or <http://users.hol.gr/~dck/gcmain.htm>
  7.  
  8. ; ****************************************************************
  9.  
  10. ; TAB size is 3
  11.  
  12. ; This gui works fine, but it is still a long way from finished.
  13. ; It does however, make gcview easier to use. Feel free to change it..
  14.  
  15. ; ================================================================
  16.  
  17. WINBIG -1 -10 640 95 ''  ; note -10 for top (see guide)
  18. wintype 00001100
  19. screen GCView
  20. ; resinfo 8 640 256
  21. BOX 0 0 0 0 out button
  22.  
  23. xOnLoad
  24.     Local scheight/winheight/barheight
  25.  
  26.     screentog = 0    ; screen2front toggle
  27.     loadedas = NORMAL
  28.     start     = 0
  29.     frames = 60
  30.     file = ''
  31.     loadall = ON
  32.     andir = PINGPONG
  33.     dmode = BG
  34.  
  35.     extract #this guipath mypath
  36.  
  37.     palette = 0
  38.     setgad #this 20 hide ; palette lv
  39.     JoinFile $mypath Palettes PalPath
  40.     lvuse #this 20
  41.     lvdir #$PalPath
  42.  
  43.     fcount = 0
  44.     savepath = T:
  45.     savebase = GCPic
  46.     savename = ''
  47.  
  48.     makescreen GCView 3 'Gui4Cli Gui 4 GCView by dck@hol.gr'
  49.  
  50.     ; start gcview - should be in the same dir as us
  51.     ifexists port ~gcview
  52.         joinfile $mypath gcview gcvname
  53.         run $gcvname
  54.         wait port gcview 100
  55.         if $$retcode > 0
  56.             ezreq 'Could not launch GCView!\n' Abort ''
  57.             guiquit #this
  58.         endif
  59.     endif
  60.  
  61.     ; get our screen height
  62.     scheight     = 256
  63.     barheight = 12
  64.     call gcview info pubscreen GCView
  65.     tempvar = $$call.ret
  66.     parsevar tempvar
  67.     if $$parse.total > 3
  68.         scheight     = $$parse.3
  69.         barheight = $$parse.5
  70.     endif
  71.  
  72.     ; open window right below menu bar & get actual height
  73.     ; changegad #this 0 -1 $barheight 0 95 '' ; doesn't work.. ?
  74.     guiopen #this
  75.     info gui #this
  76.     winheight = $$win.h
  77.  
  78.     ; move screen down..
  79.     scpos = $($scheight - $barheight - $winheight)
  80.     movescreen #this 0 $scpos    ; new function
  81.     call gcview set pointer on
  82.  
  83.     ; set my palette, if available
  84.     ifexists file guis:tools/palette/gray
  85.         guiload guis:tools/palette/gray gcview.gc
  86.     endif
  87.  
  88.     ; notify keys
  89.     call gcview notify RMB Gui4Cli 'gosub gcview.gc do_rmb'
  90.     ; call gcview notify R78 Gui4Cli 'gosub gcview.gc speed_inc'
  91.     ; call gcview notify R79 Gui4Cli 'gosub gcview.gc speed_dec'
  92.  
  93. xOnQuit
  94.     guiclose #this
  95.     killscreen GCView
  96.     call gcview quit force
  97.  
  98. xOnRMB
  99.     gosub #this do_rmb
  100.  
  101. ; -----------------------------------------------------------
  102. ;        RMB routines
  103. ; -----------------------------------------------------------
  104.  
  105. xRoutine do_rmb
  106.     if $screentog = 0
  107.         guiscreen gcview.gc back
  108.         screentog = 1
  109.     else
  110.         guiscreen gcview.gc front
  111.         screentog = 0
  112.     endif
  113.  
  114. ; xRoutine speed_inc
  115. ;     call gcview set speed 
  116.  
  117. ; xRoutine speed_dec
  118.  
  119.  
  120. ; -----------------------------------------------------------
  121. ;        crop & tile 
  122. ; -----------------------------------------------------------
  123.  
  124. XICON 273 0 :icn/crop
  125.     gadhelp 'Crops the picture/anim to the size you have marked'
  126.     call gcview crop mypic
  127.     guiscreen gcview.gc front
  128.  
  129. ; -----------------------------------------------------------
  130. ;    Tile 
  131. ; -----------------------------------------------------------
  132. XICON 273 15 :icn/mtile
  133.     gosub #this tilepic 1
  134.  
  135. XICON 273 30 :icn/tile
  136.     gosub #this tilepic 0
  137.  
  138. xRoutine tilepic mirror     ; if mirror=1 then do mirror tile
  139.     guiwindow #this wait
  140.  
  141.     if $type = ANIM
  142.         if $mirror = 1
  143.             call gcview tile mypic MIRROR
  144.         else
  145.             call gcview tile mypic
  146.         endif
  147.  
  148.     else
  149.         ; if there is a box, get size and crop it..
  150.         call gcview info boxsize mypic
  151.         info = $$call.ret
  152.         parsevar info
  153.         if $$parse.2 > 0
  154.             call gcview crop mypic
  155.         endif
  156.  
  157.         call gcview rename mypic brush
  158.         call gcview create mypic 640 512 8
  159.         call gcview open mypic
  160.         call gcview close brush
  161.         call gcview set palette mypic brush
  162.         if $mirror = 1
  163.             call gcview tile brush mypic MIRROR
  164.         else
  165.             call gcview tile brush mypic
  166.         endif
  167.         call gcview unload brush
  168.     endif
  169.  
  170.     guiwindow #this resume
  171.     guiscreen gcview.gc front
  172.  
  173. ; -----------------------------------------------------------
  174. ;    4 way mirror tile (for making bgnd patterns)
  175. ; -----------------------------------------------------------
  176.  
  177. XICON 273 45 :icn/mirror            ; do 4 way mirror
  178.     local w/d/h/sw/sh
  179.  
  180.     if $type = ANIM
  181.         flash ; not for anims..
  182.         stop
  183.     endif
  184.  
  185.     ; get sizes
  186.     call gcview info size mypic
  187.     size = $$call.ret
  188.     parsevar size
  189.     w = $$parse.0
  190.     h = $$parse.1
  191.     d = $$parse.2
  192.     sw == $w * 2
  193.     sh == $h * 2
  194.  
  195.     ; prepare background for tiling..
  196.     call gcview rename mypic brush
  197.     call gcview create mypic $sw $sh $d
  198.     call gcview open mypic
  199.     call gcview close brush
  200.     call gcview set palette mypic brush
  201.  
  202.     ; paste & flip & paste...
  203.     call gcview paste brush mypic 0 0
  204.     call gcview flip brush horizontal
  205.     call gcview paste brush mypic $w 0
  206.     call gcview flip brush vertical
  207.     call gcview paste brush mypic $w $h
  208.     call gcview flip brush horizontal
  209.     call gcview paste brush mypic 0 $h
  210.  
  211.     ; finished..
  212.     call gcview unload brush
  213.     guiscreen gcview.gc front
  214.  
  215. ; -----------------------------------------------------------
  216. ;        Flip and rotate buttons
  217. ; -----------------------------------------------------------
  218.  
  219. XICON 303 0 :icn/HFlip
  220.     call gcview flip mypic horizontal
  221.  
  222. XICON 303 15 :icn/VFlip
  223.     call gcview flip mypic vertical
  224.  
  225. XICON 303 30 :icn/RRotate
  226.     call gcview rotate mypic right
  227.  
  228. XICON 303 45 :icn/LRotate
  229.     call gcview rotate mypic left
  230.  
  231.  
  232. ; -----------------------------------------------------------
  233. ;    PAN
  234. ; -----------------------------------------------------------
  235.  
  236. ; ------------- Vertical
  237.  
  238. XICON 334 45 :icn/vpan
  239.     call gcview pan mypic MIRROR VERTICAL
  240.  
  241. XICON 333 30 :icn/vpanNoMirr
  242.     call gcview pan mypic VERTICAL
  243.  
  244. ; ------------ Horizintal
  245.  
  246. XICON 333 0 :icn/panNoMirr
  247.     call gcview pan mypic
  248.  
  249. XICON 333 15 :icn/pan
  250.     call gcview pan mypic MIRROR
  251.  
  252.  
  253. ; -----------------------------------------------------------
  254. ;    SAVE, QUIT...
  255. ; -----------------------------------------------------------
  256. ; ------------ normal save
  257.  
  258. XICON 605 4 :icn/save
  259.     local fname/fileline
  260.     if $file < ' '
  261.         file = T:GCPic
  262.     endif
  263.  
  264.     ; store the current line in lv, so we can go back to it
  265.     ; after refreshing the lv 
  266.     lvuse #this 1
  267.     fileline = $$lv.line
  268.  
  269.     ; try to be clever.. Use previously saved file's path
  270.     if $savename > ''
  271.         extract savename path savename
  272.         extract file file fname
  273.         joinfile $savename $fname fname
  274.     else
  275.         fname = $file
  276.     endif
  277.  
  278.     savename = ''
  279.     call gcview move pubscreen GCView 0 15
  280.     ReqFile -1 -1 300 -40 'Save current picture:' SAVE savename #$fname
  281.     call gcview move pubscreen GCView 0 $scpos
  282.  
  283.     if $savename > ''
  284.         ifexists file $savename
  285.             ezreq 'File already exists:\n- $savename\nOverwite ?' OverWrite|Cancel choice
  286.             if $choice = 0
  287.                 stop ; user cancelled
  288.             endif
  289.         endif
  290.         guiwindow #this wait
  291.         call gcview save mypic '$savename'
  292.         guiwindow #this resume
  293.  
  294.         ; refresh the dir, and go to previously current line
  295.         lvdir refresh
  296.         lvmove #$fileline
  297.         lvgo #$fileline
  298.         lvmulti on
  299.  
  300.     endif
  301.  
  302. ; ------------ Clear & quit
  303.  
  304. XICON 605 19 :icn/clear
  305.     ; unload all pics and anims (keep palettes)
  306.     call gcview unload #PIC
  307.     call gcview unload #ANIM
  308.  
  309. XICON 605 34 :icn/quit
  310.     local choice
  311.     ezreq 'Quit GCView ?' 'Quit|CANCEL' choice
  312.     if $choice = 1
  313.         guiquit #this
  314.     endif
  315.  
  316. ; ------------ Open/Close WB
  317.  
  318. XICON 605 54 :icn/wbtog
  319.     ifexists screen 'Workbench'
  320.         workbench close
  321.     else
  322.         workbench open
  323.     endif
  324.  
  325. ; -----------------------------------------------------------
  326. ;        The listview
  327. ; -----------------------------------------------------------
  328.  
  329. XLISTVIEW 4 0 210 92 "" file "" 10 DIR
  330.     gadid 1
  331.     gadfont #mono 8 000
  332.     attr lvfilter "~(#?.info)"            ; set filter - no icons
  333.     gosub #this showfile
  334.     guiscreen gcview.gc front
  335.     lvmulti none
  336.     lvmove #$$lv.line
  337.     lvmulti on
  338.  
  339. xRoutine showfile ; show $file - also used from view icon
  340.     gosub gcview.gc gettype
  341.     if $type != NONE
  342.     and $type != ANIM
  343.  
  344.         if $dmode = BG                            ; normal background
  345.             call gcview rename mypic oldpic
  346.             call gcview load $file mypic
  347.             if $$retcode > 0    ; no memory..
  348.                 call gcview unload oldpic
  349.                 call gcview load $file mypic
  350.                 call gcview open mypic
  351.             else
  352.                 call gcview open mypic
  353.                 call gcview unload oldpic
  354.             endif
  355.             if $usepalette = ON
  356.                 call gcview set palette mypic mypal
  357.             endif
  358.             bgdir = $$lv.dir
  359.             gosub #this showinfo
  360.         else                                        ; paste brush mode
  361.             gosub GCVIEW.GC pastebrush
  362.         endif
  363.  
  364.     elseif $type = ANIM
  365.         if $dmode = BG
  366.             bgdir = $$lv.dir
  367.             gosub #this playanim 0            ; 0=load as many frames as posible
  368.             if $usepalette = ON
  369.                 call gcview set palette mypic mypal
  370.             endif
  371.             gosub #this showinfo
  372.         else                                        ; paste anims onto each other
  373.             gosub GCVIEW.GC pastebrush
  374.         endif
  375.  
  376.     else
  377.         ; use default gui to handle file
  378.         guiload guis:tools/rtn/filepop $file
  379.         gosub #this showinfo
  380.  
  381.     endif
  382.  
  383.  
  384. xLVDirHook 1
  385.     lvuse #this 1
  386.     setscreentitle #this '$$lv.dir'
  387.  
  388. ; -----------------------------------------------------------
  389. ;    routine to paste brush into edit box
  390. ; -----------------------------------------------------------
  391.  
  392. xroutine pastebrush
  393.     if $file H= 'FORM????ANIM' ; ANIM
  394.         call gcview anload $file brush 0 1000 FORWARD
  395.     else
  396.         call gcview load $file brush
  397.     endif
  398.     ; store dir
  399.     extract file path brushdir
  400.  
  401.     ; get edit box size
  402.     call gcview info boxsize mypic
  403.     info = $$call.ret
  404.     parsevar info
  405.     x = $$parse.0
  406.     y = $$parse.1
  407.     w = $$parse.2
  408.     h = $$parse.3
  409.     if $w <= 0            ; no box
  410.         ezreq 'Please draw Edit Box first\nby click-dragging mouse.\nBrush will be sized and\npositioned accordingly' OK ''
  411.         stop
  412.     endif
  413.  
  414.     ; adjust & paste brush
  415.     call gcview resize brush $w $h
  416.     call gcview paste brush mypic $x $y
  417.     call gcview unload brush
  418.     guiscreen gcview.gc front
  419.  
  420. ; -----------------------------------------------------------
  421. ;        routine to get picture file types
  422. ; -----------------------------------------------------------
  423.  
  424. xRoutine gettype
  425.     readvar $file 0 16 header        ; read the header
  426.     set deeptrans off
  427.     ; add here any other formats you have datatypes for
  428.     type = NONE
  429.     docase $header
  430.         case S= 'FORM????ILBM' ; IFF
  431.         case S= "??????JFIF"      ; JPEG
  432.         case S= "ÿØÿÄ"              ; JPEG
  433.         case S= "GIF"              ; GIF
  434.         case S= "?PNG"              ; PNG
  435.             type = PIC
  436.             break
  437.         case S= 'FORM????ANIM' ; ANIM
  438.             type = ANIM
  439.     endcase
  440.     set deeptrans on
  441.  
  442. ; -----------------------------------------------------------
  443. ;    View selected files
  444. ; -----------------------------------------------------------
  445.  
  446. XICON 240 0 ":icn/View"
  447.     StopView = 0                ; flag to abort viewing
  448.  
  449.     ; install notify command
  450.     call gcview notify V32 Gui4Cli 'gosub gcview.gc ViewNext'
  451.     call gcview notify V13 Gui4Cli 'gosub gcview.gc ViewNext'
  452.  
  453.     lvuse #this 1
  454.     lvmulti first
  455.     gosub #this ViewRtn
  456.  
  457. xRoutine ViewNext
  458.     lvuse #this 1
  459.     lvmulti off
  460.     lvmulti next
  461.     gosub #this ViewRtn
  462.  
  463. xRoutine ViewRtn    ; actually show the file, or stop
  464.     if $$lv.line > ''
  465.     and $StopView = 0
  466.         gosub #this showfile            ; same routine as the LV itself
  467.     else
  468.         call gcview unload #PIC
  469.         call gcview unload #ANIM
  470.         call gcview delnotify V13
  471.         call gcview delnotify V32
  472.         guiscreen gcview.gc front
  473.         stop
  474.     endif
  475.  
  476. ; -----------------------------------------------------------
  477. ;        Delete file
  478. ; -----------------------------------------------------------
  479.  
  480. XICON 240 15 ":icn/Delete"
  481.     lvuse #this 1
  482.     lvaction delete REQ
  483.  
  484. ; -----------------------------------------------------------
  485. ;        listview controls
  486. ; -----------------------------------------------------------
  487.  
  488. XBUTTON 216 0 20 15 "P"
  489.     lvuse #this 1
  490.     lvdir parent
  491.     setscreentitle #this '$$lv.dir'
  492.     
  493. XBUTTON 216 15 20 15 "D"
  494.     lvuse #this 1
  495.     lvdir disks
  496.     setscreentitle #this Devices
  497.  
  498. XBUTTON 216 30 20 15 "A"
  499.     lvuse #this 1
  500.     lvmulti all
  501.  
  502. XBUTTON 216 45 20 15 "N"
  503.     lvuse #this 1
  504.     lvmulti none
  505.  
  506. XBUTTON 216 60 20 15 "<"
  507.     lvuse #this 1
  508.     lvmove -1000
  509.  
  510. XBUTTON 216 75 20 15 "R"
  511.     lvuse #this 1
  512.     lvdir refresh
  513.  
  514. ; ---------------------------------------------------------
  515. ;    status box
  516. ; ---------------------------------------------------------
  517.  
  518. TEXT 370 2 225 14 "" 100 BOX
  519. gadid 10
  520.  
  521. ; -----------------------------------------------------------
  522. ;        anims
  523. ; -----------------------------------------------------------
  524.  
  525. ;* BOX 309 17 231 52 in button
  526.  
  527. XCHECKBOX 444 42 30 15 "LoadAll" loadall "ON" "OFF" ON
  528.     gadid 2
  529.     if $loadall == ON
  530.         setgad #this 3/4 on
  531.     else
  532.         setgad #this 3/4 off
  533.     endif
  534.  
  535. XHSLIDER 422 18 146 11 "Start" start 0 100 0 "%ld"
  536.     gadid 3
  537.     gosub #this checklength
  538.  
  539. XHSLIDER 422 29 146 11 "Long" frames 0 60 60 "%ld"
  540.     gadid 4
  541.     gosub #this checklength
  542.  
  543. xroutine checklength
  544.     remain = $($frtotal - $start)
  545.     if $frames > $remain
  546.         frames = $remain
  547.         update #this 4 $frames
  548.     endif
  549.  
  550. XICON 475 42 :icn/Backward
  551.     if $loadedas = LOADALL
  552.         call gcview set direction mypic backward
  553.     endif
  554.     andir = BACKWARD
  555.  
  556. XICON 505 42 :icn/forward
  557.     call gcview set direction mypic forward
  558.     andir = FORWARD
  559.  
  560. XICON 536 42 :icn/pingpong
  561.     if $loadedas = LOADALL
  562.         call gcview set direction mypic ping
  563.     endif
  564.     andir = PINGPONG
  565.  
  566. XICON 474 57 ":icn/AddFrame"        ; add a frame
  567.     call gcview addframe mypic
  568.     gosub #this showinfo
  569.     ; guiscreen #this front
  570.     ; guiscreen gcview.gc front
  571.  
  572. XICON 505 57 ":icn/DelFrame<"        ; delete frame from end
  573.     call gcview info anim mypic
  574.     info = $$call.ret
  575.     parsevar info
  576.     if $$parse.tot > 1
  577.         call gcview delframe mypic $($$parse.1 - 1) 1
  578.     endif
  579.     gosub #this showinfo
  580.  
  581. XICON 535 57 ":icn/DelFrame>"        ; delete frame from start
  582.     call gcview delframe mypic 0 1
  583.     gosub #this showinfo
  584.  
  585. XICON 444 57 :icn/RRotate            ; reload with new settings
  586.     if $file > ''
  587.         gosub #this playanim 1
  588.         gosub #this showinfo
  589.     endif
  590.  
  591. xRoutine playanim userange            ; play anim - if userange=1, use the
  592.     call gcview unload mypic        ; start/frame values as set
  593.     if $loadall == ON
  594.         loadedas = LOADALL
  595.         if $userange = 1
  596.             call gcview anload $file mypic $start $frames $andir
  597.         else
  598.             call gcview anload $file mypic 0 1000 $andir
  599.         endif
  600.     else
  601.         loadedas = NORMAL
  602.         call gcview load $file mypic
  603.     endif
  604.     call gcview open mypic
  605.     guiscreen gcview.gc front
  606.  
  607. ; -----------------------------------------------------------
  608. ;        update info display
  609. ; -----------------------------------------------------------
  610.  
  611. xroutine showinfo
  612.     local info
  613.     extract file file name
  614.  
  615.     if $type = ANIM
  616.         call gcview info anim mypic
  617.         info = $$call.ret
  618.         parsevar info
  619.         frtotal    = $$parse.0
  620.         frstart    = $$parse.1
  621.         frloaded = $$parse.2
  622.  
  623.         if $frloaded > 0
  624.             update #this 10 '$name ($frtotal\f) LOADED:$frloaded'
  625.         else
  626.             update #this 10 '$name : $frtotal'
  627.         endif
  628.  
  629.         start     = $frstart
  630.         frames = $frloaded
  631.         changearg #this 3 7 $frtotal
  632.         changearg #this 4 7 $frtotal
  633.         update #this 3 $frstart
  634.         update #this 4 $frloaded
  635.  
  636.         redraw #this
  637.         ; use sizes from box
  638.         ; partredraw #this 309 18 234 46
  639.  
  640.     else
  641.         update #this 10 '$type : $name'
  642.  
  643.     endif
  644.  
  645. ; -----------------------------------------------------------
  646. ;        add brushes
  647. ; -----------------------------------------------------------
  648.  
  649. XCYCLER 237 75 116 15 "" dmode
  650.     CSTR "Bgnd"        BG
  651.     CSTR 'Brush'    BR
  652.  
  653.     lvuse #this 1
  654.     if $dmode = BG
  655.         lvdir #$bgdir
  656.     else
  657.         lvdir #$brushdir
  658.     endif
  659.  
  660. ; -----------------------------------------------------------
  661. ;        use palette
  662. ; -----------------------------------------------------------
  663.  
  664. XICON 303 60 :icn/palette
  665.     call gcview move pubscreen GCView 0 0 
  666.     ReqFile -1 -1 300 -40 'Choose a palette' LOAD palname ''
  667.     call gcview move pubscreen GCView 0 160
  668.     ifexists file $palname
  669.         call gcview unload mypal
  670.         call gcview load $palname mypal
  671.     endif
  672.  
  673. XCHECKBOX 333 60 20 15 "" usepalette "ON" "" OFF
  674.     gadid 9
  675.     ifexists file ~$palname
  676.         ezreq 'Please choose a palette!\n' "OK" ""
  677.         update #this 9 0
  678.     endif
  679.  
  680. ; -----------------------------------------------------------
  681. ;    zoom to screen
  682. ;    - if there is an edit box, zoom the contents
  683. ;    - otherwise fit the picture to the screen
  684. ; -----------------------------------------------------------
  685.  
  686. XICON 273 60 :icn/Zoom
  687.     local x/y/w/h
  688.  
  689.     ; get edit box size
  690.     call gcview info boxsize mypic
  691.     info = $$call.ret
  692.     parsevar info
  693.     x = $$parse.0
  694.     y = $$parse.1
  695.     w = $$parse.2
  696.     h = $$parse.3
  697.  
  698.     if $w <= 0                                ; no box - zoom the whole picture
  699.         call gcview info size mypic
  700.         size = $$call.ret
  701.         parsevar size
  702.         w = $$parse.0
  703.         h = $$parse.1
  704.         x = 0
  705.         y = 0
  706.     endif
  707.  
  708.     guiwindow #this wait
  709.     call gcview zoom mypic $x $y $w $h
  710.     guiwindow #this resume
  711.     guiscreen gcview.gc front
  712.  
  713. ; -----------------------------------------------------------
  714. ;    Palette presets handling
  715. ;    - make a list of available palettes & browse through them
  716. ; -----------------------------------------------------------
  717.  
  718. XLISTVIEW 2 0 210 92 "" palfile '' 10 DIR
  719.     gadid 20
  720.  
  721. XICON 605 69 :icn/nextpal
  722.     lvuse #this 20
  723.     lvmulti none
  724.     lvgo #$palette
  725.     if $$lv.line = ''
  726.         palette = 0
  727.         lvgo #0
  728.     endif
  729.     lvmulti on
  730.     lvmulti first
  731.     guiload $palfile gcview.gc
  732.     ++palette
  733.  
  734.  
  735.  
  736.